package org.room402.entity.chat;

import cn.hutool.json.JSONUtil;
import lombok.Builder;
import lombok.Data;
import org.room402.constant.chat.MessageAction;

import java.time.LocalDateTime;

@Data
@Builder
public class MessageEvent {
    /**
     * 消息产生者ID
     */
    private String originId;
    /**
     * 消息接收者ID
     */
    private String targetId;
    /**
     * 消息动作
     */
    private MessageAction action;

    /**
     * 消息内容
     */
    private String content;

    /**
     * 消息产生时间
     */
    private LocalDateTime createTime;

    public static MessageEvent form(String originId, String targetId, MessageAction action, String content) {
        return MessageEvent.builder()
                .originId(originId)
                .targetId(targetId)
                .action(action)
                .content(content)
                .createTime(LocalDateTime.now())
                .build();
    }

    public static MessageEvent form(String originId, String targetId, MessageAction action, Object content) {
        return form(originId, targetId, action, JSONUtil.toJsonStr(content));
    }
}
